<?php
/**
 * Created By base
 * Author: Virus
 * Date: 2020/3/11
 * Time: 14:30
 */

namespace app\common\lib;


class Arr
{
    /**
     * @desc 无限极分类
     * @param $data
     * @return array
     */
    public static function getTree($data)
    {
        $items = [];
        foreach ($data as $v) {
            $v['son']        = [];
            $items[$v['id']] = $v;
        }

        foreach ($items as $id => $item) {
            $items[$item['pid']]['son'][] = &$items[$id];
        }

        return isset($items[0]['son']) ? $items[0]['son'] : [];
    }
}